/*
*  Copyright 2012 m4f10
*
*  This file is part of uScan.
*  uScan is free software: you can redistribute it and/or modify it under the
*  terms of the GNU General Public License as published by the 
*  Free Software Foundation, either version 3 of the License, or (at your option)
*  any later version.
*
*    uScan is distributed in the hope that it will be useful, 
*    but WITHOUT ANY WARRANTY; without even the implied warranty of 
*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
* 
*    See the GNU General Public License for more details.
*
*    You should have received a copy of the GNU General Public License 
*    along with uScan. If not, see http://www.gnu.org/licenses/.
*/
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package uscan;

import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.logging.Level;
import java.util.logging.Logger;


/**
 *
 * @author m4f10
 */
public class Main extends javax.swing.JFrame {

    
    UScanSettings settings;
    UScanMain     main;
    protected boolean isScanStarted;
    /**
     * Creates new form Main
     */
    public Main() {
        settings = new UScanSettings();
        isScanStarted = false;
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        scroll = new javax.swing.JScrollPane();
        tResult = new javax.swing.JTextArea();
        jLabel6 = new javax.swing.JLabel();
        tAddress = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        bScan = new javax.swing.JButton();
        cRegular = new javax.swing.JCheckBox();
        cValue = new javax.swing.JCheckBox();
        cArray = new javax.swing.JCheckBox();
        pProgress = new javax.swing.JProgressBar();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        mSettingsMenu = new javax.swing.JMenu();
        jMenuItem1 = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("WebDiscovery - $_GET[] Variables Discovery");

        jLabel4.setForeground(new java.awt.Color(255, 0, 0));
        jLabel4.setName("lErreur"); // NOI18N

        jLabel5.setText("uScan - $_GET[''] Variables Scanner");

        tResult.setColumns(20);
        tResult.setRows(5);
        scroll.setViewportView(tResult);
        tResult.getAccessibleContext().setAccessibleName("Results");
        tResult.getAccessibleContext().setAccessibleParent(tResult);

        jLabel6.setText("Results:");

        jLabel1.setText("Target URL: ");

        bScan.setText("Scan!");
        bScan.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                bScanMouseClicked(evt);
            }
        });

        cRegular.setSelected(true);
        cRegular.setText("Regular scan");
        cRegular.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cRegularActionPerformed(evt);
            }
        });

        cValue.setText("Value Injection");

        cArray.setText("Array Injection");

        pProgress.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        pProgress.setDoubleBuffered(true);
        pProgress.setName("pProgress"); // NOI18N

        jMenu1.setText("File");
        jMenuBar1.add(jMenu1);

        mSettingsMenu.setText("Settings");
        mSettingsMenu.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                mSettingsMenuMouseReleased(evt);
            }
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                mSettingsMenuMouseClicked(evt);
            }
            public void mousePressed(java.awt.event.MouseEvent evt) {
                mSettingsMenuMousePressed(evt);
            }
        });
        mSettingsMenu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mSettingsMenuActionPerformed(evt);
            }
        });
        mSettingsMenu.addMenuKeyListener(new javax.swing.event.MenuKeyListener() {
            public void menuKeyPressed(javax.swing.event.MenuKeyEvent evt) {
                mSettingsMenuMenuKeyPressed(evt);
            }
            public void menuKeyReleased(javax.swing.event.MenuKeyEvent evt) {
            }
            public void menuKeyTyped(javax.swing.event.MenuKeyEvent evt) {
            }
        });

        jMenuItem1.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_S, java.awt.event.InputEvent.SHIFT_MASK | java.awt.event.InputEvent.CTRL_MASK));
        jMenuItem1.setText("Scanner settings");
        jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem1ActionPerformed(evt);
            }
        });
        mSettingsMenu.add(jMenuItem1);

        jMenuBar1.add(mSettingsMenu);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel5)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(scroll)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel6)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(pProgress, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(bScan, javax.swing.GroupLayout.PREFERRED_SIZE, 140, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(tAddress)
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel1)
                                    .addGroup(layout.createSequentialGroup()
                                        .addGap(11, 11, 11)
                                        .addComponent(cRegular)
                                        .addGap(18, 18, 18)
                                        .addComponent(cValue)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addComponent(cArray)))
                                .addGap(0, 0, Short.MAX_VALUE))))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(66, 66, 66)
                        .addComponent(jLabel4)
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(33, 33, 33)
                .addComponent(jLabel5)
                .addGap(18, 18, 18)
                .addComponent(jLabel1)
                .addGap(5, 5, 5)
                .addComponent(tAddress, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cValue)
                    .addComponent(cArray)
                    .addComponent(cRegular))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(bScan, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 69, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(pProgress, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel6)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(scroll, javax.swing.GroupLayout.PREFERRED_SIZE, 169, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel4))
        );

        jLabel4.getAccessibleContext().setAccessibleName("lErreur");
        jLabel5.getAccessibleContext().setAccessibleName("Title");
        jLabel6.getAccessibleContext().setAccessibleName("Results");
        tAddress.getAccessibleContext().setAccessibleName("addresse");
        jLabel1.getAccessibleContext().setAccessibleName("jAddresse");
        bScan.getAccessibleContext().setAccessibleName("bScan");

        pack();
    }// </editor-fold>//GEN-END:initComponents

    
    
    private void bScanMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_bScanMouseClicked
        if(!isScanStarted)
        {
            isScanStarted = true;
            this.bScan.setText("Stop!");
            this.main = new UScanMain(this);
            main.launchUScan();
        }
        else
        {
            this.main.prog.forceFinish();
            this.main.killThread();
            this.bScan.setText("Scan!");
            isScanStarted = false;
        }
    }//GEN-LAST:event_bScanMouseClicked

    private void cRegularActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cRegularActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_cRegularActionPerformed

    private void mSettingsMenuMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_mSettingsMenuMouseClicked
        // On affiche les options
      
    }//GEN-LAST:event_mSettingsMenuMouseClicked

    private void mSettingsMenuMenuKeyPressed(javax.swing.event.MenuKeyEvent evt) {//GEN-FIRST:event_mSettingsMenuMenuKeyPressed
        
    }//GEN-LAST:event_mSettingsMenuMenuKeyPressed

    private void mSettingsMenuMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_mSettingsMenuMousePressed
        // TODO add your handling code here:
    }//GEN-LAST:event_mSettingsMenuMousePressed

    private void mSettingsMenuMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_mSettingsMenuMouseReleased
        
    }//GEN-LAST:event_mSettingsMenuMouseReleased

    private void mSettingsMenuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mSettingsMenuActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_mSettingsMenuActionPerformed

    private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem1ActionPerformed
       UScanSettingsForm formSettings = new UScanSettingsForm(this.settings);
        formSettings.main(this.settings);
    }//GEN-LAST:event_jMenuItem1ActionPerformed

    
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Main.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Main.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Main.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Main.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Main().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    protected javax.swing.JButton bScan;
    protected javax.swing.JCheckBox cArray;
    protected javax.swing.JCheckBox cRegular;
    protected javax.swing.JCheckBox cValue;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JMenu mSettingsMenu;
    protected javax.swing.JProgressBar pProgress;
    private javax.swing.JScrollPane scroll;
    protected javax.swing.JTextField tAddress;
    protected javax.swing.JTextArea tResult;
    // End of variables declaration//GEN-END:variables
}
